package com.cms.dbUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringToCap {

	
	/**
	 * 功能：转化驼峰string首字母小写用来表示字段属性
	 * eg string_abc -->>>>stringAbc
	 * @param str
	 * @return
	 */
	 static String initcapEent(String str) {
		
		//将带有下划线的名称转成驼峰形式
		StringBuilder sb = new StringBuilder(str);
        Matcher mc = Pattern.compile("_").matcher(str);
        int i = 0;
        while (mc.find()) {
            int position = mc.end() - (i++);
            sb.replace(position - 1, position + 1, sb.substring(position, position + 1).toUpperCase());
        }
	
		return sb.toString();
	}
	 
	 
	 /**
	 * 功能：将输入字符串的首字母改成大写
	 * 并将数据库表名转成不带"_"的类名
	 * 一般作用为类名
	 *  eg string_abc -->>>>StringAbc
	 * @param str
	 * @return
	 */
		static String initcap(String str) {
			
			//将带有下划线的名称转成驼峰形式
			StringBuilder sb = new StringBuilder(str);
	        Matcher mc = Pattern.compile("_").matcher(str);
	        int i = 0;
	        while (mc.find()) {
	            int position = mc.end() - (i++);
	            sb.replace(position - 1, position + 1, sb.substring(position, position + 1).toUpperCase());
	        }
		
			char[] ch = sb.toString().toCharArray();
			if (ch[0] >= 'a' && ch[0] <= 'z') {
				ch[0] = (char) (ch[0] - 32);
			}
			

			return new String(ch);
		}
	 

}
